package org.particlethink.model;


import org.particlethink.entry.DeliverStatus;
import org.particlethink.handler.DeliverStatusHandler;
import tk.mybatis.mapper.annotation.ColumnType;
import tk.mybatis.mapper.annotation.KeySql;

import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;

@Table(name = "delivers")
public class Deliver {//发货单
    @Id
    @KeySql(useGeneratedKeys = true)
    private Integer id;
    private String no; // 发货流水号
    private Date createdAt;
    private Date confirmAt; // 供应商确认时间
    private Date billAt;  //对账时间
    private Date acceptanceAt;//验收时间
//    private String carNumber;

    private Integer orderId;//订单id
    private String orderNo;//订单编号
    private String batchPlanNo;//批次计划编号
    private String masterPlanNo;//总计划编号
    @ColumnType(typeHandler = DeliverStatusHandler.class)
    private DeliverStatus status;
    private Integer creatorId;//创建者id 供应商人员
    private Integer projectId; // 所属项目
    private Integer supplierId;//供应商
    private Date finishAt; // 预计到达时间
    private Integer billId;  //用来关联对账单
    private String categoryId;//物料大类
    private Integer acceptanceId;//验收id

    private String remark;//待验收备注(供货商)
    private String projectRemark;//验收备注(项目人员)
    private String objectionReason;//异议原因
    private Date objectionDate; //异议时间
    private Integer objectionUserId;
    private Date discardDate;
    private Integer discardUserId;

    private String receiverName;
    private String receiverPhone;
    private String receiverAddress;

    public Deliver(
            Order order,
            Integer creatorId,
            Date finishAt,
            String remark,
            String no
    ) {
        this.no = no;
        this.createdAt = new Date();
        this.orderId = order.getId();
        this.orderNo = order.getNo();

        this.batchPlanNo = order.getBatchPlanNo();
        this.masterPlanNo = order.getMasterPlanNo();
        this.status = DeliverStatus.UnChecked;
        this.creatorId = creatorId;
        this.projectId = order.getProjectId();
        this.supplierId = order.getSupplierId();
        this.finishAt = finishAt;
        this.categoryId = order.getCategoryId();
//        this.carNumber = carNumber;
        this.remark = remark;
//        this.projectRemark = projectRemark;
//        this.objectionReason = objectionReason;
    }

    public Deliver() {
    }

//    public String getCarNumber() {
//        return carNumber;
//    }

//    public void setCarNumber(String carNumber) {
//        this.carNumber = carNumber;
//    }

    public Integer getAcceptanceId() {
        return acceptanceId;
    }

//    public void setAcceptanceId(Integer acceptanceId) {
//        this.acceptanceId = acceptanceId;
//    }


    public Integer getObjectionUserId() {
        return objectionUserId;
    }

    public void setObjectionUserId(Integer objectionUserId) {
        this.objectionUserId = objectionUserId;
    }

    public Integer getDiscardUserId() {
        return discardUserId;
    }

    public void setDiscardUserId(Integer discardUserId) {
        this.discardUserId = discardUserId;
    }


    public boolean canReAccept() {
        return this.status == DeliverStatus.Objection;
    }


    public boolean canEdit() {
        return this.status == DeliverStatus.Objection;
    }

    public boolean canAccept() {
        return this.status == DeliverStatus.UnChecked;
    }

    public boolean canReject() {
        return this.status == DeliverStatus.UnChecked || this.status == DeliverStatus.Objection;
    }

    public boolean canCreateBill() {
        return this.status == DeliverStatus.Warehoused;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    public Date getCreatedAt() {
        return createdAt;
    }

    public void setOrderId(Integer orderId) {
        this.orderId = orderId;
    }

    public Integer getOrderId() {
        return orderId;
    }

    public void setStatus(DeliverStatus status) {
        this.status = status;
    }

    public DeliverStatus getStatus() {
        return status;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getRemark() {
        return remark;
    }

    public void setCreatorId(Integer creatorId) {
        this.creatorId = creatorId;
    }

    public Integer getCreatorId() {
        return creatorId;
    }

    public String getNo() {
        return no;
    }

    public void setNo(String no) {
        this.no = no;
    }


    public Date getFinishAt() {
        return finishAt;
    }

    public void setFinishAt(Date finishAt) {
        this.finishAt = finishAt;
    }

    public Integer getProjectId() {
        return projectId;
    }

    public void setProjectId(Integer projectId) {
        this.projectId = projectId;
    }

    public boolean isSupplier(Integer supplierUserId) {
        return this.creatorId == supplierUserId;
    }

    public String getProjectRemark() {
        return projectRemark;
    }

    public void setProjectRemark(String projectRemark) {
        this.projectRemark = projectRemark;
    }

    public Date getConfirmAt() {
        return confirmAt;
    }

    public void setConfirmAt(Date confirmAt) {
        this.confirmAt = confirmAt;
    }

    public Integer getBillId() {
        return billId;
    }

    public void setBillId(Integer billId) {
        this.billId = billId;
    }

    public String getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(String categoryId) {
        this.categoryId = categoryId;
    }

    public String getObjectionReason() {
        return objectionReason;
    }

    public void setObjectionReason(String objectionReason) {
        this.objectionReason = objectionReason;
    }

    public String getOrderNo() {
        return orderNo;
    }

    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }

    public String getBatchPlanNo() {
        return batchPlanNo;
    }

    public void setBatchPlanNo(String batchPlanNo) {
        this.batchPlanNo = batchPlanNo;
    }

    public String getMasterPlanNo() {
        return masterPlanNo;
    }

    public void setMasterPlanNo(String masterPlanNo) {
        this.masterPlanNo = masterPlanNo;
    }

    public Date getBillAt() {
        return billAt;
    }

    public void setBillAt(Date billAt) {
        this.billAt = billAt;
    }


    public void setAcceptanceId(Integer acceptanceId) {
        this.acceptanceId = acceptanceId;
    }

    public Integer getSupplierId() {
        return supplierId;
    }

    public void setSupplierId(Integer supplierId) {
        this.supplierId = supplierId;
    }

    public Date getAcceptanceAt() {
        return acceptanceAt;
    }

    public void setAcceptanceAt(Date acceptanceAt) {
        this.acceptanceAt = acceptanceAt;
    }

    public Date getObjectionDate() {
        return objectionDate;
    }

    public void setObjectionDate(Date objectionDate) {
        this.objectionDate = objectionDate;
    }

    public Date getDiscardDate() {
        return discardDate;
    }

    public void setDiscardDate(Date discardDate) {
        this.discardDate = discardDate;
    }

    public String getReceiverName() {
        return receiverName;
    }

    public void setReceiverName(String receiverName) {
        this.receiverName = receiverName;
    }

    public String getReceiverPhone() {
        return receiverPhone;
    }

    public void setReceiverPhone(String receiverPhone) {
        this.receiverPhone = receiverPhone;
    }

    public String getReceiverAddress() {
        return receiverAddress;
    }

    public void setReceiverAddress(String receiverAddress) {
        this.receiverAddress = receiverAddress;
    }

    public boolean isComplete() {
        return this.status == DeliverStatus.Warehoused || this.status == DeliverStatus.Reconciled || this.status == DeliverStatus.Discard;
    }

    public boolean canRemark() {
        return this.status == DeliverStatus.UnChecked;
    }

    public boolean canCancel() {
        return this.status == DeliverStatus.UnConfirmed;
    }
}
